package com.nannybear.View;

import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.nannybear.R;

/**
 * \brief The settings screen
 * \author Audrey LOISEAU
 * \date 16-03-2015
 */

/********************************* COPYRIGHT *********************************
 * Copyright (c) 2015, Audrey LOISEAU and Benjamin LANCINOT.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *************************************************************************************/

public class SettingsScreen extends Screen {
    /********** DECLARATIONS **********/
    // Widget of view
    private RelativeLayout baby_layout, light_layout, connection_layout, main_settings, perso_settings;
    private EditText baby_name;
    private Button default_light, default_sound, connection;
    private SeekBar sound_seekbar;
    private ScrollView perso_layout;
    private LinearLayout light_seekbar, sound_layout;
    private TextView value_quiet_end, value_noise_start, value_dark_end, value_dim_start, value_dim_end, value_bright_start;
    private TextView menu_baby, menu_sound, menu_light, menu_perso, menu_connection;
    private TextView checkBox_sound_txt, checkBox_vibrator_txt, time_hour_graph, time_min_graph, hour_1_timeline, hour_2_timeline, min_1_timeline, min_2_timeline;
    private ImageView triangle_baby,triangle_sound, triangle_light, triangle_perso, triangle_co, bb_gender;
    private RadioButton btn_girl, btn_boy, btn_neutral, color_fuchsia, color_red, color_green, color_blue;
    private CheckBox check_popUp, check_sound, check_vibrator;
    private ImageButton min_up, min_down, hour_up, hour_down, hour_timeline1_up, min_timeline1_up, hour_timeline1_down ,min_timeline1_down,  hour_timeline2_up, min_timeline2_up, hour_timeline2_down ,min_timeline2_down;

    /************ METHODS ************/
    /**
     * \brief Constructor
     */
    public SettingsScreen() {
        super(R.layout.settings_screen, false, false);
    }

    /**
     * \brief Change the gender of baby
     * \param gender    The baby gender
     */
    public void changeGenderBaby(int gender) {
        // Neutral
        if (gender == 0) {
            bb_gender.setBackgroundResource(R.drawable.neutral);
        }
        // Girl
        if (gender == 1) {
            bb_gender.setBackgroundResource(R.drawable.girl);
        }
        // Boy
        if (gender == 2) {
            bb_gender.setBackgroundResource(R.drawable.boy);
        }
    }

    /**
     * \brief Checked the good radio button
     * \param value The button checked
     */
    public void checkRadioButton(String value){
        if(value.equals("neutral")){
            getBtn_neutral().setChecked(true);
            bb_gender.setBackgroundResource(R.drawable.neutral);
        }
        if(value.equals("girl")){
            getBtn_girl().setChecked(true);
            bb_gender.setBackgroundResource(R.drawable.girl);
        }
        if(value.equals("boy")){
            getBtn_boy().setChecked(true);
            bb_gender.setBackgroundResource(R.drawable.boy);
        }
    }

    /**
     * \brief Display the good layout
     * \param layout    The layout to change
     * \param visibility    The visibility value
     * \param view  The view
     */
    public void changeVisibilityLayout(String layout, int visibility, RelativeLayout view){
        if(layout != null) {
            if (layout.equals("baby")) {
                triangle_baby.setVisibility(visibility);
                baby_layout.setVisibility(visibility);
                view.setVisibility(visibility);
            }
            if (layout.equals("sound")) {
                triangle_sound.setVisibility(visibility);
                sound_layout.setVisibility(visibility);
                view.setVisibility(visibility);
            }
            if (layout.equals("light")) {
                triangle_light.setVisibility(visibility);
                light_layout.setVisibility(visibility);
                view.setVisibility(visibility);
            }
            if (layout.equals("perso")) {
                triangle_perso.setVisibility(visibility);
                view.setVisibility(visibility);
            }
            if (layout.equals("connection")) {
                triangle_co.setVisibility(visibility);
                connection_layout.setVisibility(visibility);
                view.setVisibility(visibility);
            }
        }
    }

    /**
     * \brief Change the checked box state
     * \param state The state of the checkbox
     * \param sound The state of the sound
     * \param vibrator  The state of the vibrator
     */
    public void changeCheckBoxNotification(int state, int sound, int vibrator){
        // The popUp check box is unchecked
        if(state == 2){
            checkBox_sound_txt.setTextColor(Color.parseColor("#CECECE"));
            checkBox_vibrator_txt.setTextColor(Color.parseColor("#CECECE"));
            check_popUp.setChecked(false);
            check_sound.setVisibility(View.GONE);
            check_vibrator.setVisibility(View.GONE);
        }
        // The popUp is checked
        else if(state == 1){
            check_sound.setVisibility(View.VISIBLE);
            check_vibrator.setVisibility(View.VISIBLE);
            checkBox_sound_txt.setTextColor(Color.parseColor("#000000"));
            checkBox_vibrator_txt.setTextColor(Color.parseColor("#000000"));
            check_sound.setChecked((sound == 1) ? true : false);
            check_vibrator.setChecked((vibrator == 1) ? true : false);
        }
    }

    /**
     * \brief Change the check box of the color
     * \param color The new color
     */
    public void changeCheckBoxColor(String color){
        if(color.equals("#8E3557")){
            color_fuchsia.setChecked(true);
        }
        if(color.equals("#E83040")){
            color_red.setChecked(true);
        }
        if(color.equals("#ABD9FC")){
            color_blue.setChecked(true);
        }
        if(color.equals("#34B536")){
            color_green.setChecked(true);
        }
    }

    /**
     * \brief Change the connection button
     * \param displayButton If the button need to be displayed
     */
    public void changeConnectionStatus(boolean displayButton){
        if(!displayButton){
            connection.setBackgroundResource(R.drawable.button_drawable);
            connection.setText("Restart the connection !");
            connection.setTextColor(Color.parseColor("#000000"));
            connection.setClickable(true);
        }
        else{
            connection.setBackgroundResource(R.color.white);
            connection.setText("You are Connected !");
            connection.setClickable(false);
        }
    }

    /**
     * \brief Display the time of the timeline for the two radio buttons
     * \param btn   The button
     * \param hour  The hour to displayed
     * \param min   The min to displayed
     */
    public void displayTimeTimeline(int btn, int hour, int min){
        if(btn == 1){
            hour_1_timeline.setText(String.format("%02d", hour) + " H ");
            min_1_timeline.setText(String.format("%02d",min));
        }
        else{
            hour_2_timeline.setText(String.format("%02d", hour) + " H ");
            min_2_timeline.setText(String.format("%02d",min));
        }
    }

    /**
     * \brief Display the time of the graph
     * \param hour  The hour to displayed
     * \param min   The minute to displayed
     */
    public void displayTimeGraphic(int hour, int min) {
        time_hour_graph.setText(String.format("%02d", hour) + " H ");
        time_min_graph.setText(String.format("%02d",min));
    }

    /**
     * \brief Change the value of the sound seekbar
     * \param newValue  The sound value
     */
    public void displayValueSound(int newValue){
        getValue_quiet_end().setText(String.valueOf(newValue));
        getValue_noise_start().setText(String.valueOf(newValue));
    }

    /**
     * \brief Change the value of the brightness seekbar
     * \param newValueDarkDim  The light value (between dark and dim)
     * \param newValueDimBright  The light value (between dim and bright)
     */
    public void displayValueLight(int newValueDarkDim, int newValueDimBright){
        getValue_dark_end().setText(String.valueOf(newValueDarkDim));
        getValue_dim_start().setText(String.valueOf(newValueDarkDim));
        getValue_dim_end().setText(String.valueOf(newValueDimBright));
        getValue_bright_start().setText(String.valueOf(newValueDimBright));
    }

    /**
     * \brief Show the view
     * \param thresholdTemp The value of temperature threshold
     * \param thresholdHum  The value of humidity threshold
     */
    public void display(int thresholdTemp, int thresholdHum){
        getTempButton().setBackgroundResource(getTempDrawable()[thresholdTemp]);
        getHumidityButton().setBackgroundResource(getHumDrawable()[thresholdHum]);
        getSettingsButton().setBackgroundResource(R.drawable.settings_active);
    }

    /**
     * \brief Close the view (empty)
     */
    public void close(){
    }


    /*********** ACCESSORS ***********/
    /**
     * \brief Get method for the light seekbar
     */
    public LinearLayout getLight_seekbar() {
        return light_seekbar;
    }

    /**
     * \brief Get method for the quiet end value
     */
    public TextView getValue_quiet_end() {
        return value_quiet_end;
    }

    /**
     * \brief Get method for the noise start value
     */
    public TextView getValue_noise_start() {
        return value_noise_start;
    }

    /**
     * \brief Get method for the dark end value
     */
    public TextView getValue_dark_end() {
        return value_dark_end;
    }

    /**
     * \brief Get method for the dim start value
     */
    public TextView getValue_dim_start() {
        return value_dim_start;
    }

    /**
     * \brief Get method for the dim end value
     */
    public TextView getValue_dim_end() {
        return value_dim_end;
    }

    /**
     * \brief Get method for the bright start value
     */
    public TextView getValue_bright_start() {
        return value_bright_start;
    }

    /**
     * \brief Get method for the girl button
     */
    public RadioButton getBtn_girl() {
        return btn_girl;
    }
    /**
     * \brief Get method for the connection button
     */
    public Button getConnection() {
        return connection;
    }

    /**
     * \brief Get method for the perso layout
     */
    public RelativeLayout getPerso_settings() {
        return perso_settings;
    }

    /**
     * \brief Get method for the main layout
     */
    public RelativeLayout getMain_settings() {
        return main_settings;
    }

    /**
     * \brief Get method for the perso scroll view
     */
    public ScrollView getPerso_layout() {
        return perso_layout;
    }

    /**
     * \brief Get method for the connection layout
     */
    public RelativeLayout getConnection_layout() {
        return connection_layout;
    }

    /**
     * \brief Get method for the baby menu
     */
    public TextView getMenu_baby() {
        return menu_baby;
    }

    /**
     * \brief Get method for the sound menu
     */
    public TextView getMenu_sound() {
        return menu_sound;
    }

    /**
     * \brief Get method for the light menu
     */
    public TextView getMenu_light() {
        return menu_light;
    }

    /**
     * \brief Get method for the perso menu
     */
    public TextView getMenu_perso() {
        return menu_perso;
    }

    /**
     * \brief Get method for the connection menu
     */
    public TextView getMenu_connection() {
        return menu_connection;
    }

    /**
     * \brief Get method for the sound seek bar
     */
    public SeekBar getSound_seekbar() {
        return sound_seekbar;
    }

    /**
     * \brief Get method for the light layout
     */
    public RelativeLayout getLight_layout() {
        return light_layout;
    }

    /**
     * \brief Get method for the sound layout
     */
    public LinearLayout getSound_layout() {
        return sound_layout;
    }

    /**
     * \brief Get method for the boy button
     */
    public RadioButton getBtn_boy() {
        return btn_boy;
    }

    /**
     * \brief Get method for the neutral button
     */
    public RadioButton getBtn_neutral() {
        return btn_neutral;
    }

    /**
     * \brief Set method for the neutral button
     */
    public void setBtn_neutral(RadioButton btn_neutral) {
        this.btn_neutral = btn_neutral;
    }

    /**
     * \brief Set method for the boy button
     */
    public void setBtn_boy(RadioButton btn_boy) {
        this.btn_boy = btn_boy;
    }

    /**
     * \brief Set method for the dim end value
     */
    public void setValue_dim_end(TextView value_dim_end) {
        this.value_dim_end = value_dim_end;
    }

    /**
     * \brief Set method for the bright start value
     */
    public void setValue_bright_start(TextView value_bright_start) {
        this.value_bright_start = value_bright_start;
    }

    /**
     * \brief Set method for the baby menu
     */
    public void setMenu_baby(TextView menu_baby) {
        this.menu_baby = menu_baby;
    }

    /**
     * \brief Set method for the sound menu
     */
    public void setMenu_sound(TextView menu_sound) {
        this.menu_sound = menu_sound;
    }

    /**
     * \brief Set method for the light menu
     */
    public void setMenu_light(TextView menu_light) {
        this.menu_light = menu_light;
    }

    /**
     * \brief Set method for the perso menu
     */
    public void setMenu_perso(TextView menu_perso) {
        this.menu_perso = menu_perso;
    }

    /**
     * \brief Set method for the connection menu
     */
    public void setMenu_connection(TextView menu_connection) {
        this.menu_connection = menu_connection;
    }

    /**
     * \brief Set method for the baby triangle
     */
    public void setTriangle_baby(ImageView triangle_baby) {
        this.triangle_baby = triangle_baby;
    }

    /**
     * \brief Set method for the sound triangle
     */
    public void setTriangle_sound(ImageView triangle_sound) {
        this.triangle_sound = triangle_sound;
    }

    /**
     * \brief Set method for the light triangle
     */
    public void setTriangle_light(ImageView triangle_light) {
        this.triangle_light = triangle_light;
    }

    /**
     * \brief Set method for the perso triangle
     */
    public void setTriangle_perso(ImageView triangle_perso) {
        this.triangle_perso = triangle_perso;
    }

    /**
     * \brief Set method for the connection triangle
     */
    public void setTriangle_co(ImageView triangle_co) {
        this.triangle_co = triangle_co;
    }

    /**
     * \brief Set method for the baby layout
     */
    public void setBaby_layout(RelativeLayout baby_layout) {
        this.baby_layout = baby_layout;
    }

    /**
     * \brief Set method for the light layout
     */
    public void setLight_layout(RelativeLayout light_layout) {
        this.light_layout = light_layout;
    }

    /**
     * \brief Set method for the connection layout
     */
    public void setConnection_layout(RelativeLayout connection_layout) {
        this.connection_layout = connection_layout;
    }

    /**
     * \brief Set method for the sound layout
     */
    public void setSound_layout(LinearLayout sound_layout) {
        this.sound_layout = sound_layout;
    }

    /**
     * \brief Set method for the perso layout
     */
    public void setPerso_layout(ScrollView perso_layout) {
        this.perso_layout = perso_layout;
    }

    /**
     * \brief Set method for the girl button
     */
    public void setBtn_girl(RadioButton btn_girl) {
        this.btn_girl = btn_girl;
    }

    /**
     * \brief Set method for the dim start value
     */
    public void setValue_dim_start(TextView value_dim_start) {
        this.value_dim_start = value_dim_start;
    }

    /**
     * \brief Set method for the dark end value
     */
    public void setValue_dark_end(TextView value_dark_end) {
        this.value_dark_end = value_dark_end;
    }

    /**
     * \brief Set method for the noise start value
     */
    public void setValue_noise_start(TextView value_noise_start) {
        this.value_noise_start = value_noise_start;
    }

    /**
     * \brief Set method for the quiet end value
     */
    public void setValue_quiet_end(TextView value_quiet_end) {
        this.value_quiet_end = value_quiet_end;
    }

    /**
     * \brief Set method for the light seekbar
     */
    public void setLight_seekbar(LinearLayout light_seekbar) {
        this.light_seekbar = light_seekbar;
    }

    /**
     * \brief Set method for the baby name
     */
    public void setBaby_name(EditText baby_name) {
        this.baby_name = baby_name;
    }

    /**
     * \brief Set method for the light default button
     */
    public void setDefault_light(Button default_light) {
        this.default_light = default_light;
    }

    /**
     * \brief Set method for the sound default button
     */
    public void setDefault_sound(Button default_sound) {
        this.default_sound = default_sound;
    }

    /**
     * \brief Set method for the baby gender
     */
    public void setBb_gender(ImageView bb_gender) {
        this.bb_gender = bb_gender;
    }

    /**
     * \brief Set method for the pop up checkbox
     */
    public void setCheck_popUp(CheckBox check_popUp) {
        this.check_popUp = check_popUp;
    }

    /**
     * \brief Set method for the sound checkbox
     */
    public void setCheck_sound(CheckBox check_sound) {
        this.check_sound = check_sound;
    }

    /**
     * \brief Set method for the vibrator checkbox
     */
    public void setCheck_vibrator(CheckBox check_vibrator) {
        this.check_vibrator = check_vibrator;
    }

    /**
     * \brief Set method for the sound txt checkbox
     */
    public void setCheckBox_sound_txt(TextView checkBox_sound_txt) {
        this.checkBox_sound_txt = checkBox_sound_txt;
    }

    /**
     * \brief Set method for the vibrator txt checkbox
     */
    public void setCheckBox_vibrator_txt(TextView checkBox_vibrator_txt) {
        this.checkBox_vibrator_txt = checkBox_vibrator_txt;
    }

    /**
     * \brief Set method for the fuchsia color checkbox
     */
    public void setColor_fuchsia(RadioButton color_fuchsia) {
        this.color_fuchsia = color_fuchsia;
    }

    /**
     * \brief Set method for the red color checkbox
     */
    public void setColor_red(RadioButton color_red) {
        this.color_red = color_red;
    }

    /**
     * \brief Set method for the green color checkbox
     */
    public void setColor_green(RadioButton color_green) {
        this.color_green = color_green;
    }

    /**
     * \brief Set method for the blue color checkbox
     */
    public void setColor_blue(RadioButton color_blue) {
        this.color_blue = color_blue;
    }

    /**
     * \brief Set method for the connection
     */
    public void setConnection(Button connection) {
        this.connection = connection;
    }

    /**
     * \brief Set method for the main settings
     */
    public void setMain_settings(RelativeLayout main_settings) {
        this.main_settings = main_settings;
    }

    /**
     * \brief Set method for the perso settings
     */
    public void setPerso_settings(RelativeLayout perso_settings) {
        this.perso_settings = perso_settings;
    }

    /**
     * \brief Set method for the minute up button
     */
    public void setMin_up(ImageButton min_up) {
        this.min_up = min_up;
    }

    /**
     * \brief Set method for the minutes down button
     */
    public void setMin_down(ImageButton min_down) {
        this.min_down = min_down;
    }

    /**
     * \brief Set method for the hour up button
     */
    public void setHour_up(ImageButton hour_up) {
        this.hour_up = hour_up;
    }

    /**
     * \brief Set method for the hour down button
     */
    public void setHour_down(ImageButton hour_down) {
        this.hour_down = hour_down;
    }

    /**
     * \brief Set method for the hour on the graph
     */
    public void setTime_hour_graph(TextView time_hour_graph) {
        this.time_hour_graph = time_hour_graph;
    }

    /**
     * \brief Set method for the minute on the graph
     */
    public void setTime_min_graph(TextView time_min_graph) {
        this.time_min_graph = time_min_graph;
    }

    /**
     * \brief Set method for the hour 1 on the timeline
     */
    public void setHour_1_timeline(TextView hour_1_timeline) {
        this.hour_1_timeline = hour_1_timeline;
    }

    /**
     * \brief Set method for the hour 2 on the timeline
     */
    public void setHour_2_timeline(TextView hour_2_timeline) {
        this.hour_2_timeline = hour_2_timeline;
    }

    /**
     * \brief Set method for the minute 1 on the timeline
     */
    public void setMin_1_timeline(TextView min_1_timeline) {
        this.min_1_timeline = min_1_timeline;
    }

    /**
     * \brief Set method for the minute 2 on the timeline
     */
    public void setMin_2_timeline(TextView min_2_timeline) {
        this.min_2_timeline = min_2_timeline;
    }

    /**
     * \brief Set method for the hour 1 up button
     */
    public void setHour_timeline1_up(ImageButton hour_timeline1_up) {
        this.hour_timeline1_up = hour_timeline1_up;
    }

    /**
     * \brief Set method for the hour 2 down button
     */
    public void setMin_timeline2_down(ImageButton min_timeline2_down) {
        this.min_timeline2_down = min_timeline2_down;
    }

    /**
     * \brief Set method for the minute 1 up button
     */
    public void setMin_timeline1_up(ImageButton min_timeline1_up) {
        this.min_timeline1_up = min_timeline1_up;
    }

    /**
     * \brief Set method for the hour 1 down button
     */
    public void setHour_timeline1_down(ImageButton hour_timeline1_down) {
        this.hour_timeline1_down = hour_timeline1_down;
    }

    /**
     * \brief Set method for the minute 1 down button
     */
    public void setMin_timeline1_down(ImageButton min_timeline1_down) {
        this.min_timeline1_down = min_timeline1_down;
    }

    /**
     * \brief Set method for the hour 2 up button
     */
    public void setHour_timeline2_up(ImageButton hour_timeline2_up) {
        this.hour_timeline2_up = hour_timeline2_up;
    }

    /**
     * \brief Set method for the minute 2 up button
     */
    public void setMin_timeline2_up(ImageButton min_timeline2_up) {
        this.min_timeline2_up = min_timeline2_up;
    }

    /**
     * \brief Set method for the hour 2 down button
     */
    public void setHour_timeline2_down(ImageButton hour_timeline2_down) {
        this.hour_timeline2_down = hour_timeline2_down;
    }
}
